
<script type="text/javascript">
// ********************* Grid {@$grid_name@} START
var _tm = '{$_tm}';
var _transit_vars_par = ''{foreach from=$_transit_vars item=tvar_value key=tvar_key} + '&' + '{$tvar_key}=' + encodeURIComponent('{$tvar_value}'){/foreach};
var {@$grid_name@}_additional_parameters_par = ''{foreach from=${@$grid_name@}_additional_parameters item=ap_var_value key=ap_var_key} + '&' + '{$ap_var_key}={$ap_var_value}'{/foreach};
{literal}
function submit_ajax_grid_{@$grid_name@}(page) {
{/literal}
	var pars = '{@$grid_name@}_grid_page=' + page + '&' + '_tm=' + _tm + _transit_vars_par + {@$grid_name@}_additional_parameters_par;
{literal}
	fade_out_div();
	var myAjax = new Ajax.Request(
                                    "ajax/grids/{@$grid_name@}_grid.php",
                                    {
                                                method: 'get',
                                                onComplete: {@$grid_name@}_result,
                                                onSuccess: {@$grid_name@}_on_success,
                                                onFailure: {@$grid_name@}_on_failure,
												parameters: pars
                                    }          );
}


function {@$grid_name@}_result(req, json) {
	if (json) {
		var old_tm = _tm;
		_tm = json._tm;

		// refreshing _tm on all links that are outside of updated area
		for (var i=0; i < document.links.length; i++) {
 		  	document.links[i].href = document.links[i].href.replace(old_tm, _tm);
		}


		if (json.result_code == 1) { // OK
				switch(json.command) {
					case 'redirect':
						window.location = json.command_value;
						break;
					case 'show' :
					default :
						grid_div = $('{@$grid_name@}_grid_div');
						grid_div.innerHTML = req.responseText;
						break;
				}
		} else {
				// something is wrong
				if (_site_mode == 0) {
					//if in development mode - show the output anyway (if any).
					grid_div = $('{@$grid_name@}_grid_div');
					grid_div.innerHTML = req.responseText;
				}
		}
	} else {
		// no result_code, some serious error/exception occured.
		if (_site_mode == 1) {
			window.location = _server_error_page;
		} else {
			//if in development mode - show the output anyway (if any).
			grid_div = $('{@$grid_name@}_grid_div');
			grid_div.innerHTML = req.responseText;
		}
	}
}


function fade_out_div() {
	var overlay = $('{@$grid_name@}_overlay');
	var grid_div = $('{@$grid_name@}_grid_div');

	Position.clone(grid_div, overlay)
	var image = $('{@$grid_name@}_waiting');

	overlay.style.display = 'block';
	var image_top_offset = Math.round((overlay.offsetHeight - image.height) / 2);
	image.style.marginTop = image_top_offset + 'px';
}


function fade_in_div() {
	var overlay = $('{@$grid_name@}_overlay');
	overlay.style.display = 'none';
}


function {@$grid_name@}_on_success() {
	fade_in_div();
}


function {@$grid_name@}_on_failure() {
	fade_in_div();
}


function {@$grid_name@}_page_change(page) {
	submit_ajax_grid_{@$grid_name@}(page);
}


{/literal}
// ********************* Grid {@$grid_name@} END
</script>

<div id="{@$grid_name@}_grid_div">
	<!-- *** CUT top -->
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="metallic_grid_top_table" >
        <tr>
            <td>
                <div class="metallic_grid_title">{@$grid_name@}</div>
            </td>
        </tr>
        <tr>
            <td>
				<table width="100%" border="0" cellspacing="0" cellpadding="0" class="metallic_paginator">
					<tr>
						<td width="34%">
							{if ${@$grid_name@}_total_pages > 1}
							<table border="0" cellspacing="0" cellpadding="2" class="metallic_pg_page_of_table">
								<tr>
									<td valign="middle">{if ${@$grid_name@}_first_page}<a href="{${@$grid_name@}_first_page}" onclick="submit_ajax_grid_{@$grid_name@}({${@$grid_name@}_first_page_num}); return false;"><img src="img/modules/grid_html_tpl_static_ajax_metallic/page_first_blue.png" alt="First page" border="0" /></a>{else}<img src="img/modules/grid_html_tpl_static_ajax_metallic/page_first.png" alt="First page" border="0" />{/if}</td>
									<td valign="middle">{if ${@$grid_name@}_prev_page}<a href="{${@$grid_name@}_prev_page}" onclick="submit_ajax_grid_{@$grid_name@}({${@$grid_name@}_prev_page_num}); return false;"><img src="img/modules/grid_html_tpl_static_ajax_metallic/page_prev_blue.png" alt="Previous page" border="0" /></a>{else}<img src="img/modules/grid_html_tpl_static_ajax_metallic/page_prev.png" alt="Previous page" border="0" />{/if}</td>
									<td class="metallic_pg_page_of" valign="middle">{if ${@$grid_name@}_total_pages}Page {${@$grid_name@}_current_page} of {${@$grid_name@}_total_pages}{/if}</td>
									<td valign="middle">{if ${@$grid_name@}_next_page}<a href="{${@$grid_name@}_next_page}" onclick="submit_ajax_grid_{@$grid_name@}({${@$grid_name@}_next_page_num}); return false;"><img src="img/modules/grid_html_tpl_static_ajax_metallic/page_next_blue.png" alt="Next page" border="0" /></a>{else}<img src="img/modules/grid_html_tpl_static_ajax_metallic/page_next.png" alt="Next page" border="0" />{/if}</td>
									<td valign="middle">{if ${@$grid_name@}_last_page}<a href="{${@$grid_name@}_last_page}" onclick="submit_ajax_grid_{@$grid_name@}({${@$grid_name@}_last_page_num}); return false;"><img src="img/modules/grid_html_tpl_static_ajax_metallic/page_last_blue.png" alt="Last page" border="0" /></a>{else}<img src="img/modules/grid_html_tpl_static_ajax_metallic/page_last.png" alt="Last page" border="0" />{/if}</td>
								</tr>
							</table>
							{/if}
						</td>
						<td class="metallic_pg_jump_to_page" width="33%" align="center">{if ${@$grid_name@}_records_to} Records {${@$grid_name@}_records_from}-{${@$grid_name@}_records_to} of {${@$grid_name@}_records_total}{/if}</td>
						<td class="metallic_pg_records" width="33%" align="right">
							{if ${@$grid_name@}_total_pages > 1}
							<table border="0" cellspacing="2" cellpadding="0">
								<tr>
									<td>Jump to page</td>
									<td>
										<form class="metallic_pg_page_select" action="{${@$grid_name@}_jump_to_page_action}" method="get" enctype="application/x-www-form-urlencoded">
											<table width="100%" border="0" cellspacing="0" cellpadding="0">
												<tr>
													<td>
														<select name="{@$grid_name@}_grid_page" id="{@$grid_name@}_field_page" onchange="{@$grid_name@}_page_change(this.options[this.selectedIndex].value); return false;">
															{foreach from=${@$grid_name@}_jump_to_page_arr item={@$grid_name@}_page_num}
															<option value="{${@$grid_name@}_page_num}"{if ${@$grid_name@}_page_num == ${@$grid_name@}_current_page} selected="selected"{/if}>{${@$grid_name@}_page_num}</option>
															{/foreach}
														</select>
													</td>
													<td><noscript>&nbsp;<input name="submit" type="image" src="img/modules/grid_html_tpl_static_ajax_metallic/page_go.png" alt="go" /></noscript></td>
												</tr>
											</table>
										</form>
									</td>
								</tr>
							</table>
							{else}
							&nbsp;
							{/if}
						</td>
					</tr>
				</table>
            </td>
        </tr>
        <tr>
            <td>
                <table width="100%"  border="0" cellspacing="1" cellpadding="2" class="metallic_grid_table">
                    <thead>
                        <tr> {@section name=i loop=$cols_number@}
                            <th align="center" class="metallic_grid_header" nowrap="nowrap">&nbsp;Column {@$smarty.section.i.index@}&nbsp;</th>
                            {@/section@}
                            {@foreach from=$link_cols item=col@}
                            <th class="metallic_grid_header">&nbsp;</th>
                            {@/foreach@} </tr>
                    </thead>
                    <tbody>
                    {foreach from=${@$grid_name@}_prows item=row}
                    <tr class="metallic_grid_body" onmouseover="this.className='metallic_grid_body_over';return true;" onmouseout="this.className='metallic_grid_body';return true;"> {@section name=i loop=$cols_number@}
                        <td align="center">{if $row.cols.{@$smarty.section.i.index@} != NULL}{$row.cols.{@$smarty.section.i.index@}}{else}&nbsp;{/if}</td>
                        {@/section@}
                        {@foreach from=$link_cols item=col key=name@}
                        <td align="center" width="1" class="metallic_grid_link">&nbsp;&nbsp;<a href="{@$col.target_page@}?{@$col.capture@}={$row.lc_vals.{@$name@}}">{@$name@}</a>&nbsp;&nbsp;</td>
                        {@/foreach@} </tr>
                    {foreachelse}
                    <tr class="metallic_grid_body">
                        <td colspan="{@$cols_number@}" align="left">No items</td>
                        {@foreach from=$link_cols item=col@}
                        <td>&nbsp;</td>
                        {@/foreach@} </tr>
          				{assign var="${@$grid_name@}_prows_count"  value=1}
                    {/foreach}
                   <!-- Following can be used to pad with empty rows to grid's page size
                {if ${@$grid_name@}_prows_count}
                	{assign var=sub value=0}
                {else}
                	{assign var=sub value=1}                
                {/if}
				{math equation="${@$grid_name@}_page_size - rc - $sub" rc=${@$grid_name@}_prows_count assign=rc}
				{section name=aa loop=$rc}
				<tr class="metallic_grid_body">
                    <td colspan="{@$cols_number@}">&nbsp;</td>
					{@foreach from=$link_cols item=col key=name@}
					<td>&nbsp;</td>
					{@/foreach@}
				</tr>
				{/section}
 -->
                    </tbody>

                </table>
            </td>
        </tr>
<tr>
            <td>
				<table width="100%" border="0" cellspacing="0" cellpadding="0" class="metallic_paginator">
					<tr>
						<td width="34%">
							{if ${@$grid_name@}_total_pages > 1}
							<table border="0" cellspacing="0" cellpadding="2" class="metallic_pg_page_of_table">
								<tr>
									<td valign="middle">{if ${@$grid_name@}_first_page}<a href="{${@$grid_name@}_first_page}" onclick="submit_ajax_grid_{@$grid_name@}({${@$grid_name@}_first_page_num}); return false;"><img src="img/modules/grid_html_tpl_static_ajax_metallic/page_first_blue.png" alt="First page" border="0" /></a>{else}<img src="img/modules/grid_html_tpl_static_ajax_metallic/page_first.png" alt="First page" border="0" />{/if}</td>
									<td valign="middle">{if ${@$grid_name@}_prev_page}<a href="{${@$grid_name@}_prev_page}" onclick="submit_ajax_grid_{@$grid_name@}({${@$grid_name@}_prev_page_num}); return false;"><img src="img/modules/grid_html_tpl_static_ajax_metallic/page_prev_blue.png" alt="Previous page" border="0" /></a>{else}<img src="img/modules/grid_html_tpl_static_ajax_metallic/page_prev.png" alt="Previous page" border="0" />{/if}</td>
									<td class="metallic_pg_page_of" valign="middle">{if ${@$grid_name@}_total_pages}Page {${@$grid_name@}_current_page} of {${@$grid_name@}_total_pages}{/if}</td>
									<td valign="middle">{if ${@$grid_name@}_next_page}<a href="{${@$grid_name@}_next_page}" onclick="submit_ajax_grid_{@$grid_name@}({${@$grid_name@}_next_page_num}); return false;"><img src="img/modules/grid_html_tpl_static_ajax_metallic/page_next_blue.png" alt="Next page" border="0" /></a>{else}<img src="img/modules/grid_html_tpl_static_ajax_metallic/page_next.png" alt="Next page" border="0" />{/if}</td>
									<td valign="middle">{if ${@$grid_name@}_last_page}<a href="{${@$grid_name@}_last_page}" onclick="submit_ajax_grid_{@$grid_name@}({${@$grid_name@}_last_page_num}); return false;"><img src="img/modules/grid_html_tpl_static_ajax_metallic/page_last_blue.png" alt="Last page" border="0" /></a>{else}<img src="img/modules/grid_html_tpl_static_ajax_metallic/page_last.png" alt="Last page" border="0" />{/if}</td>
								</tr>
							</table>
							{/if}
						</td>
						<td class="metallic_pg_jump_to_page" width="33%" align="center">{if ${@$grid_name@}_records_to} Records {${@$grid_name@}_records_from}-{${@$grid_name@}_records_to} of {${@$grid_name@}_records_total}{/if}</td>
						<td class="metallic_pg_records" width="33%" align="right">
							{if ${@$grid_name@}_total_pages > 1}
							<table border="0" cellspacing="2" cellpadding="0">
								<tr>
									<td>Jump to page</td>
									<td>
										<form action="{${@$grid_name@}_jump_to_page_action}" method="get" enctype="application/x-www-form-urlencoded">
											<table width="100%" border="0" cellspacing="0" cellpadding="0">
												<tr>
													<td>
														<select name="{@$grid_name@}_grid_page" id="{@$grid_name@}_field_page" onchange="{@$grid_name@}_page_change(this.options[this.selectedIndex].value); return false;">
															{foreach from=${@$grid_name@}_jump_to_page_arr item={@$grid_name@}_page_num}
															<option value="{${@$grid_name@}_page_num}"{if ${@$grid_name@}_page_num == ${@$grid_name@}_current_page} selected="selected"{/if}>{${@$grid_name@}_page_num}</option>
															{/foreach}
														</select>
													</td>
													<td><noscript>&nbsp;<input name="submit" type="image" src="img/modules/grid_html_tpl_static_ajax_metallic/page_go.png" alt="go" /></noscript></td>
												</tr>
											</table>
										</form>
									</td>
								</tr>
							</table>
							{else}
							&nbsp;
							{/if}
						</td>
					</tr>
				</table>
            </td>
        </tr>
    </table>
	<!-- *** CUT botton -->    
</div>
<div class="metallic_ajax_overlay_grid" id="{@$grid_name@}_overlay" style="display:none; position: absolute; z-index: 90;" align="center"><img src="img/modules/grid_html_tpl_static_ajax_metallic/indicator_medium.gif" onclick="return true;" id="{@$grid_name@}_waiting" alt="" /></div>

